package stack

import (
	"jvm/instructions/base"
	"jvm/rtda"
)

// SWAP Swap the top two operand stack values
type SWAP struct{ base.NoOperandsInstruction }

/*
bottom -> top
[...][c][b][a]
          \/
          /\
         V  V
[...][c][a][b]
*/

func (s *SWAP) Execute(jFrame *rtda.JFrame) {
	stack := jFrame.OperandStack()
	slot1 := stack.PopSlot()
	slot2 := stack.PopSlot()
	stack.PushSlot(slot1)
	stack.PushSlot(slot2)
}
